import 'package:dog_read/pages/book/tabs/bookshelf.dart';
import 'package:dog_read/pages/book/tabs/category_books_tab.dart';
import 'package:dog_read/pages/book/tabs/latest_book_tab.dart';
import 'package:flutter/material.dart';
import './tabs/recommend_tab.dart';

class Book extends StatefulWidget {
  @override
  _BookState createState() => _BookState();
}

class _BookState extends State<Book> with SingleTickerProviderStateMixin {
  final _tabLength = 4;
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: this._tabLength, initialIndex: 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              pinned: true,
              floating: true,
              expandedHeight: 100.0,
              leading: Container(
                  padding: EdgeInsets.all(10),
                  child: Image.asset(
                    "images/icon.jpg",
                    height: 40,
                  )),
              actions: <Widget>[
                Container(
                    color: Theme.of(context).primaryColor,
                    // margin: EdgeInsets.only(right: 0),
                    child: RaisedButton.icon(
                      highlightColor: Theme.of(context).primaryColor,
                      elevation: 0,
                      color: Theme.of(context).primaryColor,
                      label: Text(
                        "搜书",
                        style: TextStyle(fontSize: 18),
                      ),
                      icon: Icon(
                        Icons.search,
                      ),
                      onPressed: () {
                        Navigator.pushNamed(context, "/book/search");
                      },
                    ))
              ],
              bottom: TabBar(
                  controller: _tabController,
                  isScrollable: true,
                  unselectedLabelColor: Colors.black38,
                  indicatorColor: Colors.black54,
                  indicatorSize: TabBarIndicatorSize.label,
                  indicatorWeight: 1.0,
                  tabs: <Widget>[
                    Tab(
                      icon: Text("书架",
                          style: TextStyle(fontWeight: FontWeight.w700)),
                    ),
                    Tab(
                      icon: Text(
                        "推荐",
                        style: TextStyle(fontWeight: FontWeight.w700),
                      ),
                    ),
                    Tab(
                      icon: Text("最新",
                          style: TextStyle(fontWeight: FontWeight.w700)),
                    ),
                    Tab(
                      icon: Text("分类",
                          style: TextStyle(fontWeight: FontWeight.w700)),
                    ),
                  ]),
            ),
          ];
        },
        body: TabBarView(
          controller: _tabController,
          children: <Widget>[
            Bookshelf(),
            BookHome(),
            LatestBookHome(),
            CateBooks()
          ],
        ),
      ),
    );
  }
}

class SliverListDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        child: SliverList(
      delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
        return Text("测试下");
      }, childCount: 100),
    ));
  }
}
